package dbops

import "database/sql"

//创建用户表
func CreateUserTable(db *sql.DB) error {
	_, err := db.Exec(`CREATE TABLE IF NOT EXISTS user (
	    user_id INT(64) NOT NULL AUTO_INCREMENT COMMENT '用户id',
	    login_name VARCHAR(64) NULL DEFAULT NULL,
	    pwd VARCHAR(64) NULL DEFAULT NULL,
		name VARCHAR(64) NULL DEFAULT '未设置名称',
	    created TIMESTAMP NOT NULL DEFAULT current_timestamp,
	    write_time TIMESTAMP NOT NULL DEFAULT current_timestamp,
	    PRIMARY KEY (user_id)
	)AUTO_INCREMENT = 10000`)
	return err
}

//创建视频列表
func CreateUserVideoTable(db *sql.DB) error {
	_, err := db.Exec(`CREATE TABLE IF NOT EXISTS user_video (
     video_id VARCHAR(64) PRIMARY KEY NOT NULL,
	 user_id INT(64) NOT NULL,
	 name TEXT,
	 created TIMESTAMP NOT NULL DEFAULT current_timestamp,
     write_time TIMESTAMP NOT NULL DEFAULT current_timestamp
)`)
	return err
}

//创建评论列表
func CreateVideoCommentTable(db *sql.DB) error {
	_, err := db.Exec(`CREATE TABLE IF NOT EXISTS video_comment (
     comment_id VARCHAR(64) PRIMARY KEY NOT NULL,
     video_id VARCHAR(64)  NOT NULL,
	 comment_user_id INT(64) NOT NULL,
 	 content TEXT,
	 created TIMESTAMP NOT NULL DEFAULT current_timestamp,
     write_time TIMESTAMP NOT NULL DEFAULT current_timestamp
)`)
	return err
}

//创建会话列表
func CreateSessionTable(db *sql.DB) error {
	_, err := db.Exec(`CREATE TABLE IF NOT EXISTS sessions (
     session_id VARCHAR(64) PRIMARY KEY NOT NULL,
     user_id VARCHAR(64) ,
     session TEXT NOT NULL,
	 created TIMESTAMP NOT NULL DEFAULT current_timestamp,
     write_time TIMESTAMP NOT NULL DEFAULT current_timestamp
)`)
	return err
}

//const UserTable = `CREATE TABLE IF NOT EXISTS user (
//    user_id INT(64) NOT NULL AUTO_INCREMENT COMMENT '用户id',
//    login_name VARCHAR(64) NULL DEFAULT NULL,
//    pwd VARCHAR(64) NULL DEFAULT NULL,
//	name VARCHAR(64) NULL DEFAULT '未设置名称',
//    created TIMESTAMP NOT NULL DEFAULT current_timestamp,
//    write_time TIMESTAMP NOT NULL DEFAULT current_timestamp,
//    PRIMARY KEY (user_id)
//)AUTO_INCREMENT = 10000`

//const UserVideoTable = `create table if not exists user_video (
//     video_id varchar(64) primary key not null,
//	 user_id int(64) not null,
//	 name text,
//	 created timestamp not null default current_timestamp,
//     write_time timestamp not null default current_timestamp
//)`
//const VideoCommentTable = `create table if not exists video_comment (
//     comment_id varchar(64) primary key not null,
//     video_id varchar(64)  not null,
//	 comment_user_id int(64) not null,
// 	 content text,
//	 created timestamp not null default current_timestamp,
//     write_time timestamp not null default current_timestamp
//)`

//const SessionTable = `create table if not exists sessions (
//     session_id varchar(64) primary key not null,
//     user_id varchar(64)  not null,
//     recent_time timestamp not null,
//	 created timestamp not null default current_timestamp,
//     write_time timestamp not null default current_timestamp
//)`
